"""
non-maxima suppression in object detection
3 0.3
50.0 51.0 180.0 200.0 0.9
48.0 53.0 170.0 210.1 0.8
200.0 51.0 242.1 81.0 0.7

50.0 51.0 180.0 200.0 0.9
200.0 51.0 242.1 81.0 0.7
"""
import sys
from copy import deepcopy

def IOU(b1, b2):
    b_and = min(abs(b1[0]-b2[2]) * abs(b1[1]-b2[3]), abs(b1[2]-b2[0]) * abs(b1[3]-b2[1]))
    b_or = abs(b1[0]-b1[2])*abs(b1[1]-b1[3]) + abs(b2[0]-b2[2])*abs(b2[1]-b2[3]) - b_and
    return b_and/b_or

def find_max_idx(bbox):
    max_score = 0
    max_idx = -1
    for idx, b in enumerate(bbox):
        if b[-1]>max_score:
            max_score = b[-1]
            max_idx = idx
    return max_idx

def delete_non_max(bboxs, th, max_box):
    rtn_bboxs = []
    for b in bboxs:
        if IOU(b, max_box)<=th:
            rtn_bboxs.append(b)
    return rtn_bboxs

def NMS(bboxs, th):
    results = []
    while len(bboxs)>0:
        score_max_idx = find_max_idx(bboxs)
        max_box = deepcopy(bboxs[score_max_idx])
        results.append(max_box)
        bboxs = bboxs[:score_max_idx]+bboxs[score_max_idx+1:]

        bboxs = delete_non_max(bboxs, th, max_box)
    return results

if __name__=="__main__":
    l1 = sys.stdin.readline().strip().split()
    N, th = l1
    N, th = int(N), float(th)
    data_list = []
    for idx in range(N):
        line = sys.stdin.readline().strip().split()
        line = [float(d) for d in line]
        data_list.append(line)
    results = NMS(data_list, th)
    for l in results:
        print(' '.join(["{:.1f}".format(_l) for _l in l]))
